package accessDBProj;

import accessDBProj.MedicMgLogic;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JMenuBar;
import java.awt.GridLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import javax.swing.JRadioButton;
import java.awt.Insets;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.WindowConstants;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableRowSorter;
import java.awt.Color;
import javax.swing.JPopupMenu;

public class MedicMgMain extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JMenuBar jJMenuBar = null;

	private JPanel jP_table = null;

	private JPanel jPanel1 = null;

	private JPanel jPanel2 = null;

	private JPanel jPanel3 = null;

	private JPanel jPanel4 = null;

	private JPanel jPanel5 = null;

	private JPanel jPanel6 = null;

	private JPanel jPanel7 = null;

	private JLabel jLabel21 = null;

	private JLabel jLabel71 = null;

	private JScrollPane jScrollPane = null;

	private JScrollPane jScrollPane1 = null;

	private JTextArea jTA_CURE_HIS = null;

	private JTextArea jTA_CURE_FIELD = null;

	private JPanel jPanel8 = null;

	private JPanel jPanel9 = null;

	private JPanel jPanel10 = null;

	private JLabel jLabel = null;

	private JTextField jTF_ID = null;// 编号

	private JLabel jLabel1 = null;

	private JTextField jTF_NM = null;// 姓名

	private JLabel jLabel3 = null;

	private JTextField jTF_AGE = null;

	private JRadioButton jRa_man = null;

	private JRadioButton jRa_wom = null;

	private ButtonGroup bu1 = null; // 性别 rodiobutton 组选框@jve:decl-index=0:

	private JButton jB_search = null;

	private JButton jB_add = null;

	private JButton jB_clear = null;

	private JButton jB_del = null;

	private JLabel jLabel4 = null;

	private JTextField jTF_ADR = null;

	private JLabel jLabel5 = null;

	private JTextField jTF_TEL = null;

	private JCheckBox jCB_DIABE = null;

	private JLabel jLabel6 = null;

	private JTextField jTF_RIG_EYE = null;

	private JLabel jLabel2 = null;

	private JTextField jTF_LEF_EYE = null;

	private JScrollPane jScrollPane2 = null;

	private JTable jTab_info = null;

	private JMenu jM_file = null;

	private JMenuItem jMI_Search = null;

	private JButton jB_edit = null;

	private JMenuItem jMI_edit = null;

	private JMenuItem jMI_close = null;

	private JMenu jM_help = null;

	private JMenuItem jMI_about = null;

	private static Vector tableHead = null;

	MedicMgLogic mLogic = new MedicMgLogic();

	private Vector table_rows = new Vector();// 保存检索结果 // @jve:decl-index=0:

	private JTextField jT_DIABE = null;

	private JPopupMenu jPopupMenu = null;

	private JMenuItem jMenuItem_DELETE = null;

	/**
	 * This method initializes jJMenuBar
	 * 
	 * @return javax.swing.JMenuBar
	 */
	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.setPreferredSize(new Dimension(0, 25));
			jJMenuBar.add(getJM_file());
			jJMenuBar.add(getJM_help());
		}
		return jJMenuBar;
	}

	/**
	 * This method initializes jP_table
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJP_table() {
		if (jP_table == null) {
			jP_table = new JPanel();
			jP_table.setLayout(new BorderLayout());
			jP_table.add(getJScrollPane2(), BorderLayout.CENTER);
		}
		return jP_table;
	}

	/**
	 * This method initializes jPanel1
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			GridLayout gridLayout1 = new GridLayout();
			gridLayout1.setRows(2);
			jPanel1 = new JPanel();
			jPanel1.setLayout(gridLayout1);
			jPanel1.add(getJPanel3(), null);
			jPanel1.add(getJPanel2(), null);
		}
		return jPanel1;
	}

	/**
	 * This method initializes jPanel2
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			jPanel2 = new JPanel();
			jPanel2.setLayout(new BorderLayout());
			jPanel2.add(getJPanel4(), BorderLayout.SOUTH);
			jPanel2.add(getJPanel5(), BorderLayout.CENTER);
		}
		return jPanel2;
	}

	/**
	 * This method initializes jPanel3
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel3() {
		if (jPanel3 == null) {
			GridLayout gridLayout3 = new GridLayout();
			gridLayout3.setRows(3);
			gridLayout3.setHgap(0);
			gridLayout3.setColumns(1);
			jPanel3 = new JPanel();
			jPanel3.setLayout(gridLayout3);
			jPanel3.add(getJPanel10(), null);
			jPanel3.add(getJPanel9(), null);
			jPanel3.add(getJPanel8(), null);
		}
		return jPanel3;
	}

	/**
	 * This method initializes jPanel4
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel4() {
		if (jPanel4 == null) {
			GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
			gridBagConstraints21.gridx = 1;
			gridBagConstraints21.weightx = 1.0;
			gridBagConstraints21.ipadx = 50;
			gridBagConstraints21.ipady = 5;
			gridBagConstraints21.gridy = 0;
			GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
			gridBagConstraints11.gridx = 3;
			gridBagConstraints11.ipadx = 50;
			gridBagConstraints11.ipady = 5;
			gridBagConstraints11.weightx = 1.0;
			gridBagConstraints11.insets = new Insets(3, 0, 3, 0);
			gridBagConstraints11.gridy = 0;
			GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
			gridBagConstraints10.insets = new Insets(3, 0, 3, 0);
			gridBagConstraints10.gridy = 0;
			gridBagConstraints10.ipadx = 50;
			gridBagConstraints10.ipady = 5;
			gridBagConstraints10.weightx = 1.0;
			gridBagConstraints10.gridx = 4;
			GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
			gridBagConstraints9.gridx = 2;
			gridBagConstraints9.ipadx = 50;
			gridBagConstraints9.ipady = 5;
			gridBagConstraints9.weightx = 1.0;
			gridBagConstraints9.gridy = 0;
			GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
			gridBagConstraints8.gridx = 0;
			gridBagConstraints8.ipadx = 50;
			gridBagConstraints8.ipady = 5;
			gridBagConstraints8.insets = new Insets(0, 0, 0, 0);
			gridBagConstraints8.weightx = 1.0;
			gridBagConstraints8.gridy = 0;
			jPanel4 = new JPanel();
			jPanel4.setLayout(new GridBagLayout());
			jPanel4.setPreferredSize(new Dimension(0, 30));
			jPanel4.add(getJB_search(), gridBagConstraints8);
			jPanel4.add(getJB_add(), gridBagConstraints9);
			jPanel4.add(getJB_clear(), gridBagConstraints10);
			jPanel4.add(getJB_del(), gridBagConstraints11);
			jPanel4.add(getJB_edit(), gridBagConstraints21);
		}
		return jPanel4;
	}

	/**
	 * This method initializes jPanel5
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel5() {
		if (jPanel5 == null) {
			GridLayout gridLayout2 = new GridLayout();
			gridLayout2.setRows(1);
			gridLayout2.setHgap(1);
			gridLayout2.setColumns(1);
			jPanel5 = new JPanel();
			jPanel5.setLayout(gridLayout2);
			jPanel5.add(getJPanel6(), null);
			jPanel5.add(getJPanel7(), null);
		}
		return jPanel5;
	}

	/**
	 * This method initializes jPanel6
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel6() {
		if (jPanel6 == null) {
			BorderLayout borderLayout = new BorderLayout();
			borderLayout.setHgap(0);
			jLabel21 = new JLabel();
			jLabel21.setHorizontalAlignment(SwingConstants.LEFT);
			jLabel21.setText("\u6cbb\u7597\u7ecf\u8fc7\uff1a");
			jLabel21.setHorizontalTextPosition(SwingConstants.LEFT);
			jPanel6 = new JPanel();
			jPanel6.setLayout(borderLayout);
			jPanel6.add(jLabel21, BorderLayout.NORTH);
			jPanel6.add(getJScrollPane(), BorderLayout.CENTER);
		}
		return jPanel6;
	}

	/**
	 * This method initializes jPanel7
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel7() {
		if (jPanel7 == null) {
			jLabel71 = new JLabel();
			jLabel71.setHorizontalAlignment(SwingConstants.LEFT);
			jLabel71.setText("\u4e13\u79d1\u60c5\u51b5\uff1a");
			jLabel71.setHorizontalTextPosition(SwingConstants.LEFT);
			jPanel7 = new JPanel();
			jPanel7.setLayout(new BorderLayout());
			jPanel7.add(jLabel71, BorderLayout.NORTH);
			jPanel7.add(getJScrollPane1(), BorderLayout.CENTER);
		}
		return jPanel7;
	}

	/**
	 * This method initializes jScrollPane
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJTA_CURE_HIS());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jScrollPane1
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJScrollPane1() {
		if (jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setViewportView(getJTA_CURE_FIELD());
		}
		return jScrollPane1;
	}

	/**
	 * This method initializes jTA_CURE_HIS
	 * 
	 * @return javax.swing.JTextArea
	 */
	private JTextArea getJTA_CURE_HIS() {
		if (jTA_CURE_HIS == null) {
			jTA_CURE_HIS = new JTextArea();
			jTA_CURE_HIS.setSize(new Dimension(336, 80));
			jTA_CURE_HIS.setWrapStyleWord(true);
			jTA_CURE_HIS.setLineWrap(true);
		}
		return jTA_CURE_HIS;
	}

	/**
	 * This method initializes jTA_CURE_FIELD
	 * 
	 * @return javax.swing.JTextArea
	 */
	private JTextArea getJTA_CURE_FIELD() {
		if (jTA_CURE_FIELD == null) {
			jTA_CURE_FIELD = new JTextArea();
			jTA_CURE_FIELD.setSize(new Dimension(336, 80));
			jTA_CURE_FIELD.setWrapStyleWord(true);
			jTA_CURE_FIELD.setLineWrap(true);
		}
		return jTA_CURE_FIELD;
	}

	/**
	 * This method initializes jPanel8
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel8() {
		if (jPanel8 == null) {
			GridBagConstraints gridBagConstraints22 = new GridBagConstraints();
			gridBagConstraints22.fill = GridBagConstraints.NONE;
			gridBagConstraints22.gridy = 0;
			gridBagConstraints22.weightx = 0.0;
			gridBagConstraints22.gridx = 1;
			GridBagConstraints gridBagConstraints20 = new GridBagConstraints();
			gridBagConstraints20.fill = GridBagConstraints.NONE;
			gridBagConstraints20.gridy = 0;
			gridBagConstraints20.ipadx = 0;
			gridBagConstraints20.ipady = 0;
			gridBagConstraints20.weightx = 1.0;
			gridBagConstraints20.anchor = GridBagConstraints.WEST;
			gridBagConstraints20.gridx = 5;
			GridBagConstraints gridBagConstraints19 = new GridBagConstraints();
			gridBagConstraints19.gridx = 4;
			gridBagConstraints19.ipadx = 0;
			gridBagConstraints19.ipady = 0;
			gridBagConstraints19.gridy = 0;
			GridBagConstraints gridBagConstraints18 = new GridBagConstraints();
			gridBagConstraints18.fill = GridBagConstraints.NONE;
			gridBagConstraints18.gridy = 0;
			gridBagConstraints18.ipadx = 0;
			gridBagConstraints18.ipady = 0;
			gridBagConstraints18.weightx = 0.0;
			gridBagConstraints18.gridx = 3;
			GridBagConstraints gridBagConstraints17 = new GridBagConstraints();
			gridBagConstraints17.gridx = 2;
			gridBagConstraints17.ipadx = 0;
			gridBagConstraints17.ipady = 0;
			gridBagConstraints17.gridy = 0;
			GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
			gridBagConstraints16.gridx = 0;
			gridBagConstraints16.ipadx = 46;
			gridBagConstraints16.ipady = 7;
			gridBagConstraints16.gridy = 0;
			jLabel2 = new JLabel();
			jLabel2.setText("右眼视力：");
			jLabel2.setHorizontalTextPosition(SwingConstants.RIGHT);
			jLabel2.setPreferredSize(new Dimension(70, 16));
			jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
			jLabel6 = new JLabel();
			jLabel6.setHorizontalAlignment(SwingConstants.RIGHT);
			jLabel6.setText("左眼视力：");
			jLabel6.setPreferredSize(new Dimension(100, 16));
			jLabel6.setHorizontalTextPosition(SwingConstants.RIGHT);
			jPanel8 = new JPanel();
			jPanel8.setLayout(new GridBagLayout());
			jPanel8.add(getJCB_DIABE(), gridBagConstraints16);
			jPanel8.add(jLabel6, gridBagConstraints17);
			jPanel8.add(getJTF_RIG_EYE(), gridBagConstraints18);
			jPanel8.add(jLabel2, gridBagConstraints19);
			jPanel8.add(getJTF_LEF_EYE(), gridBagConstraints20);
			jPanel8.add(getJT_DIABE(), gridBagConstraints22);
		}
		return jPanel8;
	}

	/**
	 * This method initializes jPanel9
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel9() {
		if (jPanel9 == null) {
			GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
			gridBagConstraints15.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints15.gridy = 0;
			gridBagConstraints15.weightx = 0.0;
			gridBagConstraints15.gridx = 3;
			GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
			gridBagConstraints14.gridx = 2;
			gridBagConstraints14.gridy = 0;
			jLabel5 = new JLabel();
			jLabel5.setHorizontalAlignment(SwingConstants.RIGHT);
			jLabel5.setText("\u8054\u7cfb\u7535\u8bdd\uff1a");
			jLabel5.setHorizontalTextPosition(SwingConstants.RIGHT);
			GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
			gridBagConstraints13.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints13.gridy = 0;
			gridBagConstraints13.weightx = 0.0;
			gridBagConstraints13.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints13.gridx = 1;
			GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
			gridBagConstraints12.gridx = 0;
			gridBagConstraints12.anchor = GridBagConstraints.CENTER;
			gridBagConstraints12.weightx = 0.0;
			gridBagConstraints12.gridwidth = 1;
			gridBagConstraints12.gridy = 0;
			jLabel4 = new JLabel();
			jLabel4.setPreferredSize(new Dimension(45, 16));
			jLabel4.setHorizontalTextPosition(SwingConstants.RIGHT);
			jLabel4.setText("\u4f4f\u5740\uff1a");
			jLabel4.setHorizontalAlignment(SwingConstants.RIGHT);
			jPanel9 = new JPanel();
			jPanel9.setLayout(new GridBagLayout());
			jPanel9.add(jLabel4, gridBagConstraints12);
			jPanel9.add(getJTF_ADR(), gridBagConstraints13);
			jPanel9.add(jLabel5, gridBagConstraints14);
			jPanel9.add(getJTF_TEL(), gridBagConstraints15);
		}
		return jPanel9;
	}

	/**
	 * This method initializes jPanel10
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel10() {
		if (jPanel10 == null) {
			GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
			gridBagConstraints7.gridx = 7;
			gridBagConstraints7.insets = new Insets(0, 0, 0, 20);
			gridBagConstraints7.weightx = 1.0;
			gridBagConstraints7.anchor = GridBagConstraints.WEST;
			gridBagConstraints7.gridy = 0;
			GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
			gridBagConstraints6.gridx = 6;
			gridBagConstraints6.insets = new Insets(0, 60, 0, 0);
			gridBagConstraints6.gridy = 0;
			GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
			gridBagConstraints5.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints5.gridy = 0;
			gridBagConstraints5.weightx = 0.0;
			gridBagConstraints5.gridx = 5;
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
			gridBagConstraints4.gridx = 4;
			gridBagConstraints4.gridy = 0;
			jLabel3 = new JLabel();
			jLabel3.setHorizontalAlignment(SwingConstants.RIGHT);
			jLabel3.setText("\u5e74\u9f84\uff1a");
			jLabel3.setHorizontalTextPosition(SwingConstants.RIGHT);
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints3.gridy = 0;
			gridBagConstraints3.weightx = 0.0;
			gridBagConstraints3.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints3.gridx = 3;
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.gridx = 2;
			gridBagConstraints2.gridy = 0;
			jLabel1 = new JLabel();
			jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
			jLabel1.setText("\u59d3\u540d \uff1a");
			jLabel1.setHorizontalTextPosition(SwingConstants.RIGHT);
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints1.gridy = 0;
			gridBagConstraints1.weightx = 0.0;
			gridBagConstraints1.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints1.gridx = 1;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.insets = new Insets(0, 10, 0, 5);
			gridBagConstraints.gridy = 0;
			jLabel = new JLabel();
			jLabel.setHorizontalAlignment(SwingConstants.RIGHT);
			jLabel.setText("\u7f16\u53f7  \uff1a");
			jLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
			jPanel10 = new JPanel();
			jPanel10.setLayout(new GridBagLayout());
			jPanel10.add(jLabel, gridBagConstraints);
			jPanel10.add(getJTF_ID(), gridBagConstraints1);
			jPanel10.add(jLabel1, gridBagConstraints2);
			jPanel10.add(getJTF_NM(), gridBagConstraints3);
			jPanel10.add(jLabel3, gridBagConstraints4);
			jPanel10.add(getJTF_AGE(), gridBagConstraints5);
			jPanel10.add(getJRa_man(), gridBagConstraints6);
			jPanel10.add(getJRa_wom(), gridBagConstraints7);
			bu1 = new ButtonGroup();
			bu1.add(jRa_man);
			bu1.add(jRa_wom);
		}
		return jPanel10;
	}

	/**
	 * This method initializes jTF_ID
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTF_ID() {
		if (jTF_ID == null) {
			jTF_ID = new JTextField();
			jTF_ID.setPreferredSize(new Dimension(100, 20));
			jTF_ID.setBackground(new Color(204, 255, 255));
			jTF_ID.setHorizontalAlignment(JTextField.LEADING);
		}
		return jTF_ID;
	}

	/**
	 * This method initializes jTF_NM
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTF_NM() {
		if (jTF_NM == null) {
			jTF_NM = new JTextField();
			jTF_NM.setPreferredSize(new Dimension(150, 20));
			jTF_NM.setBackground(new Color(204, 255, 255));
		}
		return jTF_NM;
	}

	/**
	 * This method initializes jTF_AGE
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTF_AGE() {
		if (jTF_AGE == null) {
			jTF_AGE = new JTextField();
			jTF_AGE.setPreferredSize(new Dimension(40, 20));
			jTF_AGE.setBackground(new Color(204, 255, 255));
			jTF_AGE.setHorizontalAlignment(JTextField.LEADING);
		}
		return jTF_AGE;
	}

	/**
	 * This method initializes jRa_man
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getJRa_man() {
		if (jRa_man == null) {
			jRa_man = new JRadioButton();
			jRa_man.setText("\u7537\u6027");
			jRa_man.setSelected(true);
		}
		return jRa_man;
	}

	/**
	 * This method initializes jRa_wom
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getJRa_wom() {
		if (jRa_wom == null) {
			jRa_wom = new JRadioButton();
			jRa_wom.setText("\u5973\u6027");
		}
		return jRa_wom;
	}

	/**
	 * This method initializes jB_search
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJB_search() {
		if (jB_search == null) {
			jB_search = new JButton();
			jB_search.setText("查找");
			jB_search.setPreferredSize(new Dimension(60, 18));
			jB_search.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Map GUIVal = null;
					GUIVal = getGUIVal();
					table_rows = mLogic.search(GUIVal);
					try {
						Utilities.displayResultSet(jTab_info, tableHead,
								table_rows);
						jTab_info.getTableHeader().setReorderingAllowed(false);
						DefaultTableCellRenderer render = new DefaultTableCellRenderer();// 某列单元格居中显示
						render.setHorizontalAlignment(SwingConstants.CENTER);//
						jTab_info.getColumn("年龄").setCellRenderer(render);//
						jTab_info.getColumn("年龄").setMaxWidth(40);
						jTab_info.getColumn("年龄").setResizable(false);
						jTab_info.getColumn("性别").setMaxWidth(40);
						jTab_info.getColumn("性别").setResizable(false);
						jTab_info.getColumn("性别").setCellRenderer(render);
						jTab_info.getColumn("糖尿病史").setMaxWidth(60);
						jTab_info.getColumn("糖尿病史").setResizable(false);
						jTab_info.getColumn("糖尿病史").setCellRenderer(render);
						jTab_info.getColumn("糖尿病期").setMaxWidth(60);
						jTab_info.getColumn("糖尿病期").setResizable(false);
						jTab_info.getColumn("糖尿病期").setCellRenderer(render);
						jTab_info.getColumn("左眼视力").setMaxWidth(60);
						jTab_info.getColumn("左眼视力").setResizable(false);
						jTab_info.getColumn("左眼视力").setCellRenderer(render);
						jTab_info.getColumn("右眼视力").setMaxWidth(60);
						jTab_info.getColumn("右眼视力").setResizable(false);
						jTab_info.getColumn("右眼视力").setCellRenderer(render);
						// // 增加标志列并使其不可见
						jTab_info.getColumnModel().getColumn(9)
								.setPreferredWidth(0);
						jTab_info.getColumnModel().getColumn(9).setWidth(0);
						jTab_info.getColumnModel().getColumn(9).setMinWidth(0);
						jTab_info.getColumnModel().getColumn(9).setMaxWidth(0);
						// 各表项排序
						TableRowSorter sorter = new TableRowSorter(jTab_info
								.getModel());
						jTab_info.setRowSorter(sorter);
						// "编号", "姓名", "年龄", "性别", "糖尿病史","左眼视力", "右眼视力",
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
					// Auto-generated
					// Event stub
					// actionPerformed()

				}
			});
		}
		return jB_search;
	}

	/**
	 * This method initializes jB_add
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJB_add() {
		if (jB_add == null) {
			jB_add = new JButton();
			jB_add.setPreferredSize(new Dimension(60, 18));
			jB_add.setText("添加");
			jB_add.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {

					// 编号输入确认
					Map GUIVal = null;
					GUIVal = getGUIVal();
					if (GUIVal.get("jTF_ID").equals("")) {
						JOptionPane.showMessageDialog(null, "请输入记录编号以及相应信息！",
								"消息", JOptionPane.ERROR_MESSAGE);
					} else {
						// 动作确认
						int response = JOptionPane.showConfirmDialog(null,
								"确认增加编号  " + jTF_ID.getText() + " 的记录吗?",
								"增加记录确认", JOptionPane.YES_NO_OPTION);
						if (response == JOptionPane.NO_OPTION) {
							return;
						}
						// ----
						if (!mLogic.addRecord(GUIVal)) {
							JOptionPane.showMessageDialog(null, "该记录编号已存在！",
									"消息", JOptionPane.ERROR_MESSAGE);
						} else {
							JOptionPane.showMessageDialog(null, "成功插入一条记录！",
									"消息", JOptionPane.INFORMATION_MESSAGE);
						}
						// Auto-generated
						// Event stub
						// actionPerformed()
					}
				}
			});
		}
		return jB_add;
	}

	/**
	 * This method initializes jB_clear
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJB_clear() {
		if (jB_clear == null) {
			jB_clear = new JButton();
			jB_clear.setText("清空");
			jB_clear.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					clearGUIVal();
				}
			});
		}
		return jB_clear;
	}

	/**
	 * This method initializes jB_del
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJB_del() {
		if (jB_del == null) {
			jB_del = new JButton();
			jB_del.setPreferredSize(new Dimension(60, 18));
			jB_del.setText("删除");
			jB_del.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if (jTF_ID.getText().trim().equals("")) {
						JOptionPane.showMessageDialog(null, "请输入待删除记录编号！",
								"消息", JOptionPane.ERROR_MESSAGE);
					} else {
						// 动作确认
						int response = JOptionPane.showConfirmDialog(null,
								"确认删除编号  " + jTF_ID.getText() + " 的记录吗？",
								"删除记录确认", JOptionPane.YES_NO_OPTION);
						if (response == JOptionPane.NO_OPTION) {
							return;
						}
						if (mLogic.delete(jTF_ID.getText().trim())) {
							JOptionPane.showMessageDialog(null, "成功删除编号为 "
									+ jTF_ID.getText() + " 的记录！", "消息",
									JOptionPane.INFORMATION_MESSAGE);
						} else {
							JOptionPane.showMessageDialog(null, "不存在编号为 "
									+ jTF_ID.getText() + " 的记录！", "消息",
									JOptionPane.INFORMATION_MESSAGE);
						}

					}

				}

			});
		}
		return jB_del;
	}

	/**
	 * This method initializes jTF_ADR
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTF_ADR() {
		if (jTF_ADR == null) {
			jTF_ADR = new JTextField();
			jTF_ADR.setPreferredSize(new Dimension(300, 20));
		}
		return jTF_ADR;
	}

	/**
	 * This method initializes jTF_TEL
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTF_TEL() {
		if (jTF_TEL == null) {
			jTF_TEL = new JTextField();
			jTF_TEL.setPreferredSize(new Dimension(150, 20));
		}
		return jTF_TEL;
	}

	/**
	 * This method initializes jCB_DIABE
	 * 
	 * @return javax.swing.JCheckBox
	 */
	private JCheckBox getJCB_DIABE() {
		if (jCB_DIABE == null) {
			jCB_DIABE = new JCheckBox();
			jCB_DIABE.setText("\u7cd6\u5c3f\u75c5\u75c5\u53f2");
			jCB_DIABE.setPreferredSize(new Dimension(45, 24));
			jCB_DIABE.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jCB_DIABE.isSelected()) {
						jT_DIABE.setEnabled(true);
					} else {
						jT_DIABE.setText("");
						jT_DIABE.setEnabled(false);
					}
				}
			});
		}
		return jCB_DIABE;
	}

	/**
	 * This method initializes jTF_RIG_EYE
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTF_RIG_EYE() {
		if (jTF_RIG_EYE == null) {
			jTF_RIG_EYE = new JTextField();
			jTF_RIG_EYE.setText("");
			jTF_RIG_EYE.setPreferredSize(new Dimension(30, 20));
			jTF_RIG_EYE.setHorizontalAlignment(JTextField.LEFT);
		}
		return jTF_RIG_EYE;
	}

	/**
	 * This method initializes jTF_LEF_EYE
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTF_LEF_EYE() {
		if (jTF_LEF_EYE == null) {
			jTF_LEF_EYE = new JTextField();
			jTF_LEF_EYE.setHorizontalAlignment(JTextField.LEADING);
			jTF_LEF_EYE.setPreferredSize(new Dimension(30, 20));
		}
		return jTF_LEF_EYE;
	}

	/**
	 * This method initializes jScrollPane2
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJScrollPane2() {
		if (jScrollPane2 == null) {
			jScrollPane2 = new JScrollPane();
			jScrollPane2.setViewportView(getJTab_info());
		}
		return jScrollPane2;
	}

	/**
	 * This method initializes jTab_info
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getJTab_info() {
		if (jTab_info == null) {
			jTab_info = new JTable();
			jTab_info
					.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
			jTab_info.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
			jTab_info.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					int selectRows = jTab_info.getSelectedRows().length;// 取得用户所选行的行数
					// MyTableModel tableModel = (MyTableModel) jTab_info
					// .getModel();
					if (selectRows == 1) {
						int selectedRowIndex = jTab_info.getSelectedRow(); // 取得用户所选单行
						int rowid = Integer.parseInt(jTab_info.getValueAt(
								selectedRowIndex, 9).toString());
						// System.out.println("rowid "+rowid);
						// 进行相关处理
						setGUIVal(rowid);
						System.out.println("single JTable mouseClicked()");
					} else {
						System.out.println("multi JTable mouseClicked()");
					}
				}

				// 在选中的行上弹出右键菜单
				public void mousePressed(java.awt.event.MouseEvent e) {
					Point rownum = e.getPoint();// 获得鼠标点对象
					// 判断鼠标所在行是否选中
					if (jTab_info.isRowSelected(jTab_info.rowAtPoint(rownum))) {
						getJPopupMenu();
						super.mousePressed(e);
						if (e.getButton() == java.awt.event.MouseEvent.BUTTON3) {
							// System.out.println("pop click");
							jPopupMenu.show(jTab_info, e.getX(), e.getY());
						}
					}
				}

			});
		}
		return jTab_info;
	}

	/**
	 * This method initializes jM_file
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getJM_file() {
		if (jM_file == null) {
			jM_file = new JMenu();
			jM_file.setText("文件");
			jM_file.setHorizontalTextPosition(SwingConstants.CENTER);
			jM_file.setPreferredSize(new Dimension(40, 20));
			jM_file.setHorizontalAlignment(SwingConstants.CENTER);
			jM_file.add(getJMI_Search());
			jM_file.add(getJMI_edit());
			jM_file.add(getJMI_close());
		}
		return jM_file;
	}

	/**
	 * This method initializes jMI_Search
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMI_Search() {
		if (jMI_Search == null) {
			jMI_Search = new JMenuItem();
			jMI_Search.setText("检索模式");
			jMI_Search.setToolTipText("查找记录，更改记录");
		}
		return jMI_Search;
	}

	/**
	 * This method initializes jB_edit
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJB_edit() {
		if (jB_edit == null) {
			jB_edit = new JButton();
			jB_edit.setPreferredSize(new Dimension(60, 18));
			jB_edit.setText("修改");
			jB_edit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Map GUIVal = null;
					GUIVal = getGUIVal();
					if (GUIVal.get("jTF_ID").equals("")) {
						JOptionPane.showMessageDialog(null, "请输入记录编号以及相应信息！",
								"消息", JOptionPane.ERROR_MESSAGE);
					} else {
						// 动作确认
						int response = JOptionPane.showConfirmDialog(null,
								"确认修改编号  " + jTF_ID.getText() + " 的记录吗?",
								"修改记录确认", JOptionPane.YES_NO_OPTION);
						if (response == JOptionPane.NO_OPTION) {
							return;
						}
						mLogic.update(GUIVal);
						JOptionPane.showMessageDialog(null, "成功更新编号为 "
								+ jTF_ID.getText() + " 的记录！", "消息",
								JOptionPane.INFORMATION_MESSAGE);
					}
				}
			});
		}
		return jB_edit;
	}

	/**
	 * This method initializes jMI_edit
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMI_edit() {
		if (jMI_edit == null) {
			jMI_edit = new JMenuItem();
			jMI_edit.setText("新增模式");
			jMI_edit.setToolTipText("添加，更改，删除记录");
		}
		return jMI_edit;
	}

	/**
	 * This method initializes jMI_close
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMI_close() {
		if (jMI_close == null) {
			jMI_close = new JMenuItem();
			jMI_close.setText("关闭");
			jMI_close.setToolTipText("退出程序");
			jMI_close.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					// 关闭时弹出退出确认对话框
					int response = JOptionPane.showConfirmDialog(null,
							"请确认要退出程序吗？", "退出", JOptionPane.YES_NO_OPTION);
					if (response == JOptionPane.OK_OPTION) {
						System.exit(0);
					}

					// Auto-generated
					// Event stub
					// actionPerformed()

				}
			});
		}
		return jMI_close;
	}

	/**
	 * This method initializes jM_help
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getJM_help() {
		if (jM_help == null) {
			jM_help = new JMenu();
			jM_help.setPreferredSize(new Dimension(40, 20));
			jM_help.setToolTipText("");
			jM_help.setText("帮助");
			jM_help.add(getJMI_about());
		}
		return jM_help;
	}

	/**
	 * This method initializes jMI_about
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMI_about() {
		if (jMI_about == null) {
			jMI_about = new JMenuItem();
			jMI_about.setText("关于");
			jMI_about.setToolTipText("版本介绍");
			jMI_about.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JOptionPane
							.showMessageDialog(
									null,
									"MMG V0.5 \nCopyright by guanzhibin\n E-mail：pandalovepc@hotmail.com",
									"关于", JOptionPane.INFORMATION_MESSAGE);
				}
			});
		}
		return jMI_about;
	}

	/**
	 * This method initializes jT_DIABE
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJT_DIABE() {
		if (jT_DIABE == null) {
			jT_DIABE = new JTextField();
			jT_DIABE.setPreferredSize(new Dimension(25, 20));
			jT_DIABE.setEnabled(false);
		}
		return jT_DIABE;
	}

	/**
	 * This method initializes jPopupMenu
	 * 
	 * @return javax.swing.JPopupMenu
	 */
	private JPopupMenu getJPopupMenu() {
		if (jPopupMenu == null) {
			jPopupMenu = new JPopupMenu();
			jPopupMenu.add(getJMenuItem_DELETE());
		}
		return jPopupMenu;
	}

	/**
	 * This method initializes jMenuItem_DELETE
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItem_DELETE() {
		if (jMenuItem_DELETE == null) {
			jMenuItem_DELETE = new JMenuItem();
			jMenuItem_DELETE.setText("删除");
			jMenuItem_DELETE
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							int rows[] = jTab_info.getSelectedRows();

							mLogic.delete(rows, table_rows);
							System.out.println("pop delete");
						}
					});
		}
		return jMenuItem_DELETE;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				// { "编号", "姓名", "年龄", "性别", "糖尿病史","糖尿病期","左眼视力", "右眼视力",
				// "联系电话" };
				tableHead = new Vector();
				tableHead.addElement("编号");
				tableHead.addElement("姓名");
				tableHead.addElement("年龄");
				tableHead.addElement("性别");
				tableHead.addElement("糖尿病史");
				tableHead.addElement("糖尿病期");
				tableHead.addElement("左眼视力");
				tableHead.addElement("右眼视力");
				tableHead.addElement("联系电话");
				MedicMgMain thisClass = new MedicMgMain();
				// thisClass.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}

	/**
	 * This is the default constructor
	 */
	public MedicMgMain() {
		super();
		// 实例存在判断
		if (Utilities.instance) {
			JOptionPane.showMessageDialog(null, "程序已打开，请确认！", "消息",
					JOptionPane.INFORMATION_MESSAGE);
			System.exit(1);
		}
		Utilities.instance = true;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(688, 522);
		this.setIconImage(Toolkit.getDefaultToolkit().getImage(
				getClass().getResource("/MMG.PNG")));
		this.setName("frame_MedicMg");
		this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		Dimension winSize = Toolkit.getDefaultToolkit().getScreenSize(); // 屏幕分辨率
		this.setLocation((winSize.width - this.getWidth()) / 2,
				(winSize.height - this.getHeight()) / 2); // 窗口定位
		this.setJMenuBar(getJJMenuBar());
		this.setMinimumSize(new Dimension(688, 522));
		this.setContentPane(getJContentPane());
		this.setTitle("病历管理系统");
		this.addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent e) {
				// 关闭时弹出退出确认对话框
				int response = JOptionPane.showConfirmDialog(null,
						"请确认要退出程序吗？", "退出", JOptionPane.YES_NO_OPTION);
				if (response == JOptionPane.OK_OPTION) {
					System.exit(0);
				}

				// Event stub
				// windowClosing()
			}
		});
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			GridLayout gridLayout = new GridLayout();
			gridLayout.setRows(2);
			gridLayout.setHgap(0);
			gridLayout.setColumns(1);
			jContentPane = new JPanel();
			jContentPane.setLayout(gridLayout);
			jContentPane.add(getJPanel1(), null);
			jContentPane.add(getJP_table(), null);
		}
		return jContentPane;
	}

	// -----------------VIEW PG--------------------//
	/*
	 * 
	 */
	public Map getGUIVal() {
		Map map_info = new HashMap();
		map_info.put("jTF_ID", jTF_ID.getText().trim());// 编号
		map_info.put("jTF_NM", jTF_NM.getText().trim());// 姓名
		map_info.put("jTF_AGE", jTF_AGE.getText().trim());// 年龄
		map_info.put("jRa_man", String.valueOf(jRa_man.isSelected()));// 性别
		map_info.put("jCB_DIABE", String.valueOf(jCB_DIABE.isSelected()));// 糖尿病病史
		map_info.put("jT_DIABE", jT_DIABE.getText().trim());// 糖尿病期
		map_info.put("jTF_RIG_EYE", jTF_RIG_EYE.getText().trim());// 左眼视力
		map_info.put("jTF_LEF_EYE", jTF_LEF_EYE.getText().trim());// 右眼视力
		map_info.put("jTF_TEL", jTF_TEL.getText().trim());// 联系电话
		map_info.put("jTF_ADR", jTF_ADR.getText().trim());// 地址
		map_info.put("jTA_CURE_HIS", jTA_CURE_HIS.getText().trim());// 治疗经过
		map_info.put("jTA_CURE_FIELD", jTA_CURE_FIELD.getText().trim());// 专科情况
		return map_info;
	}

	/*
	 * 将jTable中单击选择的记录显示在个信息栏
	 */
	public void setGUIVal(int rowIndex) {
		Vector row = new Vector();
		row = (Vector) table_rows.get(rowIndex);
		jTF_ID.setText((String) row.get(0));
		jTF_NM.setText((String) row.get(1));
		jTF_AGE.setText((String) row.get(2));
		if (String.valueOf(row.get(3)).equals("男"))
			jRa_man.setSelected(true);
		else
			jRa_wom.setSelected(true);
		if (String.valueOf(row.get(4)).equals("有"))
			jCB_DIABE.setSelected(true);
		else
			jCB_DIABE.setSelected(false);
		jT_DIABE.setText((String) row.get(5));
		jTF_LEF_EYE.setText((String) row.get(6));
		jTF_RIG_EYE.setText((String) row.get(7));
		jTF_TEL.setText((String) row.get(8));
		jTF_ADR.setText((String) row.get(9));
		jTA_CURE_HIS.setText((String) row.get(10));
		jTA_CURE_FIELD.setText((String) row.get(11));
	}

	/*
	 * 清空信息栏
	 */
	public void clearGUIVal() {
		jTF_ID.setText("");
		jTF_NM.setText("");
		jTF_AGE.setText("");
		jRa_man.setSelected(true);
		jCB_DIABE.setSelected(false);
		jTF_LEF_EYE.setText("");
		jTF_RIG_EYE.setText("");
		jTF_TEL.setText("");
		jTF_ADR.setText("");
		jTA_CURE_HIS.setText("");
		jTA_CURE_FIELD.setText("");
	}
} // @jve:decl-index=0:visual-constraint="10,10"

